from pdf2image import convert_from_path # pip install pdf2image 以及https://gitcode.com/gh_mirrors/po/poppler-windows/tree/poppler-24.11.0
import os

if __name__ == '__main__':
    pdf_path = r"C:\Users\MaGuangSheng\Desktop\Java.pdf"
    output_dir = r"C:\Users\MaGuangSheng\Desktop\output_images"
    os.makedirs(output_dir, exist_ok=True)

    # 显式指定 poppler 的 bin 目录路径（Windows 示例）
    poppler_path = r"D:\Release-25.07.0-0\poppler-25.07.0\Library\bin"  # 修改为你的实际路径

    try:
        images = convert_from_path(
            pdf_path,
            output_folder=output_dir,
            fmt="jpg",
            poppler_path=poppler_path  # 添加此参数
        )
        print("转换成功！图片保存至：", output_dir)
    except Exception as e:
        print("转换失败：", e)